import { Injectable } from '@angular/core';
import { HOSTURL, PREFIX } from '../../config';
import { RequestClientService } from '../request-client.service';

@Injectable({
  providedIn: 'root'
})
export class NoticeService {

  constructor(
    private requestClientService: RequestClientService
  ) { }

  // 获取公告列表(非管理员)
  public async getNotices(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/QueryMyPagedList`, params);
    return res;
  }
  // 获取公告列表(管理员)
  public async getAdminNotices(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/QueryPagedList`, params);
    return res;
  }
  // 获取部门信息
  public async getOrganizations(params) {
    const res = await this.requestClientService.get(HOSTURL + `/api/services/${PREFIX}/OrganizationUnit/GetOrganizationUnits`, params);
    return res;
  }
  // 发布公告
  public async addNotice(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/Create`, params);
    return res;
  }
  // 删除自己的公告(非管理员)
  public async deleteNotices(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/BatchRemoveByCurrentUser`, params);
    return res;
  }
  // 删除公告(管理员)
  public async deleteAdminNotice(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/BatchRemove`, params);
    return res;
  }
  // 公告详情
  public async noticeDetails(id) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/QueryDetailById?input=` + id, {});
    return res;
  }
  // 标记为已读
  public async markRead(params) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/BatchMarkRead`, params);
    return res;
  }
  // 显示或隐藏
  public async showOrHide(id) {
    const res = await this.requestClientService.post(HOSTURL + `/api/services/${PREFIX}/Notices/MarkHideOrShow?input=` + id, {});
    return res;
  }


}
